package com.hxy.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hxy.common.DateUtil;
import com.hxy.common.JsonResult;
import com.hxy.dao.TrainnoteMapper;
import com.hxy.pojo.Stuffinfo;
import com.hxy.pojo.Trainnote;
import com.hxy.pojo.model.GetUtilPagerequest;
import com.hxy.pojo.vo.StuffVoResultMapAndTrainNote;
import com.hxy.pojo.vo.StuffinfoShowByIdVo;
import com.hxy.pojo.vo.StuffinfoVo;
import com.hxy.pojo.vo.TrainnoteVo;
import com.hxy.service.TrainNoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TrainNoteServiceImpl implements TrainNoteService {
    @Autowired
    private TrainnoteMapper trainnoteMapper;

    @Override
    public PageInfo<Trainnote> selectAll(Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Trainnote> trainnotes = trainnoteMapper.selectAll();
        PageInfo<Trainnote> trainnotePageInfo = new PageInfo<>(trainnotes);
        return trainnotePageInfo;
    }

    @Override
    public int addTrainNote(TrainnoteVo trainnotevo) {
        return trainnoteMapper.insert(trainnotevo);
    }

    @Override
    public PageInfo<TrainnoteVo> findTrainnoteByTJ(Integer curPage, int pageSize, String trainname, String starttime, String trainunit, String status) {
        TrainnoteVo trainnoteVo = new TrainnoteVo(trainname, starttime, trainunit, status);
        PageHelper.startPage(curPage, pageSize);
        List<TrainnoteVo> trainnotes = trainnoteMapper.findTrainnoteByTJ(trainnoteVo);
        PageInfo<TrainnoteVo> televisionPageInfo = new PageInfo<>(trainnotes);
        return televisionPageInfo;

    }

    @Override
    public int updataTrainNote(TrainnoteVo trainnotevo) {

        return trainnoteMapper.updataTrainNote(trainnotevo);
    }

    @Override
    public int deleteTrainNote(Integer id) {
        return trainnoteMapper.deleteTrainNote(id);
    }

    @Override
    public PageInfo<StuffinfoShowByIdVo> findTrainnoteStu(Integer id, Integer curPage, int pageSize) {
        PageHelper.startPage(curPage, pageSize);
        List<StuffinfoShowByIdVo> stuffinfoVos = trainnoteMapper.findTrainnoteStu(id);
        PageInfo<StuffinfoShowByIdVo> televisionPageInfo = new PageInfo<>(stuffinfoVos);
        return televisionPageInfo;
    }

    @Override
    public PageInfo<StuffVoResultMapAndTrainNote> findTrainnoteAllStu(Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<StuffVoResultMapAndTrainNote> stuffinfoVos = trainnoteMapper.findTrainnoteAllStu();
        PageInfo<StuffVoResultMapAndTrainNote> televisionPageInfo = new PageInfo<>(stuffinfoVos);
        return televisionPageInfo;
    }

    @Override
    public JsonResult findTrainnoteOne(Integer id) {
        TrainnoteVo trainnote = trainnoteMapper.selectByPrimaryKey(id);
        if (trainnote != null) {
            return new JsonResult(0, "success", trainnote);
        } else {
            return new JsonResult(1, "error", null);
        }
    }

    @Override
    public JsonResult deleteTrainNote_IndexByTidAndEid(Integer tid, Integer eid) {
        int i=trainnoteMapper.deleteTrainNote_IndexByTidAndEid(tid,eid);
        if (i>0){
            return new JsonResult(0, "success",i);
        }
        else {
            return new JsonResult(1, "fail",0);
        }
    }

    @Override
    public JsonResult addTrainNote_IndexByTidAndEid(Integer tid, Integer eid) {
        //先查询是否存在
       int i= trainnoteMapper.selectTrainNote_IndexByTidAndEid(tid,eid);
       if (i>0){
           return new JsonResult(1, "员工已经存在",null);
       }
       else {
           int j=trainnoteMapper.addTrainNote_IndexByTidAndEid(tid,eid);
           return new JsonResult(0, "success",j);
       }

    }


}
